package com.yaoli.niuke;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by siemens on 5/31/2017.
 */
public class _016_Test {
    public ArrayList<ArrayList<Integer>> FindContinuousSequence(int sum) {
        // (shou + mou)*(mou - shou + 1)=sum * 2
        //  mou + shou = y
        // mou = y - shou
        // y ( y - 2*shou - 1 ) = 2sum
        //
        ArrayList<Integer> list ;
        ArrayList<ArrayList<Integer>> res = new ArrayList<ArrayList<Integer>>();

        for(int shou = 1 ; shou <= 2*sum ; shou++){
            for(int mou = shou + 1; mou <= 2*sum; mou++){
                if(2*sum == (shou + mou)*(mou - shou + 1)){
                    list = new ArrayList<Integer>();
                    for(int i = shou ; i <= mou ; i++){
                        list.add(i);
                    }
                    res.add(list);
                }
            }
        }
        return res;
    }

    public static void main(String[] args) {
        int num[] = {1,3,2,6,4};
        _016_Test test = new _016_Test();
        test.isContinuous(num);
    }
    public boolean isContinuous(int [] numbers) {
        if(numbers.length == 0){
            return false;
        }
        Arrays.sort(numbers);

        int count = 0;
        int zeroCount = 0;
        int numPosition = 0;
        for(int i = 0 ; i < numbers.length ; i++){
            if(numbers[i] == 0){
                zeroCount++;
            }else{
                numPosition = i;
                break;
            }
        }

        for(int i = numPosition ; i < numbers.length - 1; i++){
            count = numbers[i + 1] - numbers[i] - 1 + count;
        }

        if (count == 0) {
            return true;
        }
        if(count == zeroCount){
            return true;
        }

        return false;
    }
}
